<?php
declare (strict_types = 1);

namespace app\auth\validate;

use think\Validate;

class Member extends Validate
{
    /**
     * 定义验证规则
     * 格式：'字段名'	=>	['规则1','规则2'...]
     *
     * @var array
     */	
    protected $rule = [
        'username|用户名'=>'require|max:40',
        'truename|真实姓名'=>'require|max:40',
        'password|密码'=>'min:6',
        'repassword|密码确认'=>'min:6|confirm:password',
        'email|电子邮件'=>'require|email',
        'mobile|联系方式'=>'require',
        'status'=>'normal',
        'role'=>'member'
    ];
    /**
     * 定义错误信息
     * 格式：'字段名.规则名'	=>	'错误信息'
     *
     * @var array
     */	
    protected $message = [
        'repassword.confirm'=>'两次输入的密码不一致，请检查！',
        'username.unique'=>'用户名称已经存在，请重新输入！'
    ];
    // 验证场景
    protected $scene = [
        'login' =>['username', 'password'],
        // 'register' => ['username','password','repassword'],
        'create' => ['username','password','repassword','truename','email'],
        'update' => ['username','truename','password','repassword','email']
    ];
    // edit 验证场景定义
    public function sceneRegister()
    {
    	return $this->only(['username','password','repassword'])->append('username', 'unique:member');
    }  
}
